package com.macro.mall.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.BmsSightseeingBusParam;
import com.macro.mall.dto.BmsSightseeingBusPointParam;
import com.macro.mall.model.BmsSightseeingBus;
import com.macro.mall.model.BmsSightseeingBusPoint;
import com.macro.mall.service.BmsSightseeingBusPointService;
import com.macro.mall.service.BmsSightseeingBusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 观光车点位表Controller
 * Created by macro on 2018/4/26.
 */
@Controller
@Api(tags = "BmsSightseeingBusPointController")
@Tag(name = "BmsSightseeingBusPointController", description = "观光车点位管理")
@RequestMapping("/sightseeingBusPoint")
public class BmsSightseeingBusPointController {
    @Autowired
    private BmsSightseeingBusPointService bmsSightseeingBusPointService;

    @ApiOperation("添加观光车点位")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> create(@RequestBody BmsSightseeingBusPointParam bmsSightseeingBusPointParam) {
        int count = bmsSightseeingBusPointService.create(bmsSightseeingBusPointParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }
    @ApiOperation("修改观光车")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> update(@RequestBody BmsSightseeingBusPointParam bmsSightseeingBusPointParam) {
        int count = bmsSightseeingBusPointService.update(bmsSightseeingBusPointParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }
    @ApiOperation("分页查询观光车")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<BmsSightseeingBusPoint>> getList(@RequestBody BmsSightseeingBusPointParam bmsSightseeingBusPointParam) {
        List<BmsSightseeingBusPoint> bmsSightseeingBusPointList = bmsSightseeingBusPointService.getList(bmsSightseeingBusPointParam);
        return CommonResult.success(CommonPage.restPage(bmsSightseeingBusPointList));
    }

    @ApiOperation("根据id获取观光车点位信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<BmsSightseeingBusPoint> getItem(@PathVariable Long id) {
        BmsSightseeingBusPoint bmsSightseeingBusPoint = bmsSightseeingBusPointService.getItem(id);
        return CommonResult.success(bmsSightseeingBusPoint);
    }

    @ApiOperation("删除观光车")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> delete(@RequestBody List<Long> ids) {
        int count = bmsSightseeingBusPointService.delete(ids);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }
}
